<?PHP
  $current_page = "event.php";
  $page_type = "S";
  require_once 'header.php';
?>
	<div id="page">
	  <div id="page-padding">
        <!-- start content -->	    
	    <div id="content">
	      <div id="content-padding">
            <h1>Event Management Main</h1>
            
			<?PHP
				if(!empty($_GET["search_error"])) 
					$smsg = "<font color=\"#CC0000\">{$_GET["search_error"]}</font>";
				else 
					$smsg = "";
				if(!empty($_GET["create_error"]))
					$cmsg = "<font color=\"#CC0000\">{$_GET["create_error"]}</font>";
				else
					$cmsg = "";
				if (!empty($_GET["edit_error"]))
					$emsg = "<font color=\"#CC0000\">{$_GET["edit_error"]}</font>";
				else
					$emsg = "";
				if (!empty($_GET["removal_error"]))
					$rmsg = "<font color=\"#CC0000\">{$_GET["removal_error"]}</font>";
				else
					$rmsg = "";
					
				//Form to create a new event
				echo("<p><br><b>Create:</b><fieldset><form method=\"post\" action=\"event_create.php\"><br>
				Event Stakeholder ID: <input type=\"text\" size=\"20\" maxlength=\"30\" name=\"new_sid\"> 
				Event ID: <input type=\"text\" size=\"20\" maxlength=\"8\" name=\"new_eid\">
				Event Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"new_ename\"> <br><br />
				Description: <input type=\"text\" size=\"100\" maxlength=\"500\" name=\"new_description\"> <br><br />
				Start Time: <input type=\"datetime\" name=\"new_stime\">
				End Time: <input type=\"datetime\" name=\"new_etime\"> <br><br />
				Location Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"new_lcname\"> <br><br />
				Street: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"new_street\"> 
				City: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"new_city\"> 
				State: <input type=\"text\"  size=\"20\" maxlength=\"50\" name=\"new_state\">
				Zip: <input type=\"text\" size=\"20\" maxlength=\"12\" name=\"new_zip\"> <br><br />
				Requirements: <input type=\"text\" size=\"20\" maxlength=\"20\" name=\"new_req\"> <br>
				
				<input type=\"submit\" name=\"create\" value=\"Create Event\">&nbsp&nbsp$cmsg
				</form></fieldset></p>");
				
				//Form to search for an event
				echo("<p><br><b>Search:</b><fieldset><form method=\"post\" action=\"event.php\"><br>
				Event Stakeholder ID: <input type=\"text\" size=\"20\" maxlength=\"30\" name=\"input_sid\"> 
				Event ID: <input type=\"text\" size=\"20\" maxlength=\"8\" name=\"input_eid\">
				Event Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_ename\"> <br><br />
				Location Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_lcname\"> <br> <br />
				Street: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_street\"> 
				City: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_city\"> 
				State: <input type=\"text\"  size=\"20\" maxlength=\"50\" name=\"input_state\">
				Zip: <input type=\"text\" size=\"12\" maxlength=\"12\" name=\"input_zip\">
				<input type=\"submit\" name=\"search\" value=\"Search\">&nbsp&nbsp$smsg
				</form></fieldset></p>");
				
				if (isset($_POST["input_sid"]))
					$input_sid = $_POST["input_sid"];
				if (isset($_POST["input_eid"]))
					$input_eid = $_POST["input_eid"];
				if (isset($_POST["input_ename"]))
					$input_ename = $_POST["input_ename"];
				if (isset($_POST["input_lcname"]))
					$input_lcname = $_POST["input_lcname"];
				if (isset($_POST["input_street"]))
					$input_street = $_POST["input_street"];
				if (isset($_POST["input_city"]))
					$input_city = $_POST["input_city"];
				if (isset($_POST["input_state"]))
					$input_state = $_POST["input_state"];
				if (isset($_POST["input_zip"]))
					$input_zip = $_POST["input_zip"];
					
				$whereclause = "1=1 ";

				if (isset($input_sid) and trim($input_sid) != "")
					$whereclause .= " and userid like '%$input_sid%'";
				if (isset($input_eid) and trim($input_eid) != "")
					$whereclause .= " and eventid like '%$input_eid%'";
				if (isset($input_ename) and trim($input_ename) != "")
					$whereclause .= " and ename like '%$input_ename%'";
				if (isset($input_lcname) and trim($input_lcname) != "")
					$whereclause .= " and lcname like '%$input_lcname%'";
				if (isset($input_street) and trim($input_street) != "")
					$whereclause .= " and street like '%$input_street%'";
				if (isset($input_city) and trim($input_city) != "")
					$whereclause .= " and city like '%$input_city%'";
				if (isset($input_state) and trim($input_state) != "")
					$whereclause .= " and state like '%$input_state%'";
				if (isset ($input_zip) and trim($input_zip) != "")
					$whereclause .= " and zip like '%$input_zip%'";
					
				//Create Event table
				echo("<p><br><table border = 2> 
				<tr> <th>Stakeholder ID</th><th>Event ID</th><th>Event Name</th><th>Post Date</th><th>Location Name</th>
				<th>Location</th><th>Start Time</th><th>End Time</th><th>Description</th>");
				if((isset($_SESSION['aflag']) and $_SESSION['aflag'] == "y") or (isset($_SESSION['sflag']) and $_SESSION['sflag'] == "y"))
					echo("<th>&nbsp;</th><th>&nbsp;</th>");
				echo("</tr>");
				
				//Form the query to populate the Event table
				$sql = "select UserID, EventID, Ename, Post_Date, LCName, Street, City, State, Zip, S_Time, E_Time, Description " .
					" from Event where $whereclause order by EventID";
				$result_array = execute_sql_in_oracle($sql);
				$result = $result_array["flag"];
				$cursor = $result_array["cursor"];
				if(!$result){
					display_oracle_error_message($cursor);
					die("Event query failed.");
				}
				$iterator = 0;
				while($values = oci_fetch_array($cursor)){
					$t_uid = $values[0];
					$t_eid = $values[1];
					$t_ename = $values[2];
					$t_postdate = $values[3];
					$t_lcname = $values[4];
					$t_street = $values[5];
					$t_city = $values[6];
					$t_state = $values[7];
					$t_zip = $values[8];
					$t_stime = $values[9];
					$t_etime = $values[10];
					$t_description = $values[11];
					
					$t_location = "";
					if(!empty($t_lcname) and $t_lcname != "")
						$t_location = $t_lcname . ", ";
					if(!empty($t_street) and $t_street != "")
						$t_location = $t_location . $t_street;
					if(!empty($t_city) and $t_city != "")
						$t_location = $t_location .", ". $t_city;
					if(!empty($t_state) and $t_state != "")
						$t_location = $t_location .", " . $t_state;
					if(!empty($t_zip) and $t_zip != "")
						$t_location = $t_location ." ". $t_zip;
					
					
					//Generate the 'D d-M-y' format for start, end, and post time
					$t_sdate = "";
					$t_edate = "";
					$t_pdate = "";
					if(isset($t_stime) and trim($t_stime) != "") 
						$t_sdate = date('D d-M-y', strtotime($t_stime));
					if(isset($t_etime) and trim($t_stime) != "")
						$t_edate = date('D d-M-y', strtotime($t_etime));
					if(isset($t_postdate) and trim($t_postdate) != "")
						$t_pdate = date('D d-M-Y', strtotime($t_postdate));
					
					echo("<tr> <td>$t_uid</td> <td>$t_eid</td> <td>$t_ename</td> <td>$t_pdate</td> <td>$t_lcname</td>
						<td>$t_location</td> <td>$t_sdate</td> <td>$t_edate</td> <td>$t_description</td>");
						
					if((isset($_SESSION['aflag']) and $_SESSION['aflag'] == "y") or (isset($_SESSION['sflag']) and $_SESSION['sflag'] == "y")){
						echo("<td> <A HREF=\"event_edit.php?eid=$t_eid&uid=$t_uid\">Edit</A> </td>
							<td> <A HREF=\"event_remove.php?eid=$t_eid&uid=$t_uid\">Remove</A> </td>");
					}
					echo("</tr>");
					$iterator++;


					
				}
				oci_free_statement($cursor);
				echo("</table></form> </p>");	


				
			?>
			
			
	      </div>
		</div>
	  <!-- end content --></div>
	  <div id="footer">
	    <div id="footer-pad">
	      <div class="line"></div>
		  <!-- footer and copyright notice -->
	      <p>Design by <a href="http://www.steves-templates.com">Steve's free website templates</a>.</p>
		  <!-- end footer and copyright notice -->
	    </div>
	  </div>
	</div>
  </body>
</html>